
package com.insigma.business.qrcode.soldier._provider.impl;



import com.insigma.business.qrcode.common.template.BasePagingResponse;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.common.util.ResponseUtils;
import com.insigma.business.qrcode.soldier.dto.gov.BaseProviderImpl;
import com.insigma.business.qrcode.common.template.area.ScenarioCodeEnum;
import com.insigma.business.qrcode.common.template.area.ServiceCallback;
import com.insigma.business.qrcode.soldier.entity.PlacementWordConfigDO;
import com.insigma.business.qrcode.soldier.request.PlacementWordConfigBSearcher;
import com.insigma.business.qrcode.soldier.request.PlacementWordConfigSearchRequest;
import com.insigma.business.qrcode.soldier._provider.PlacementWordConfigProvider;
import com.insigma.business.qrcode.soldier.service.PlacementWordConfigService;
import com.insigma.business.qrcode.soldier.service.impl.PlacementWordConfigDTO;
import com.insigma.business.qrcode.common.converter.PlacementWordConfigProviderConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
@Component("placementWordConfigProvider")
public class PlacementWordConfigProviderImpl extends BaseProviderImpl implements PlacementWordConfigProvider {

    @Autowired
    private PlacementWordConfigService placementWordConfigService;


    @Override
    public BasePagingResponse<List<PlacementWordConfigDTO>> searchPlacementWordConfig(final PlacementWordConfigSearchRequest searchRequest) {

        final BasePagingResponse<List<PlacementWordConfigDTO>> basePagingResponse = new BasePagingResponse<>();
        serviceTemplate.execute(basePagingResponse, new ServiceCallback() {
            @Override
            public void check() {
                BizCheckUtil.checkNotNull(searchRequest, "查询分页PlacementWordConfig的请求参数不能为空");
            }

            @Override
            public void executeService() {
                final PlacementWordConfigBSearcher placementWordConfigBSearcher = PlacementWordConfigProviderConverter.convertRequestSO2Searcher(searchRequest);
                final List<PlacementWordConfigDO> placementWordConfigDOList = placementWordConfigService.search(placementWordConfigBSearcher);
                final List<PlacementWordConfigDTO> placementWordConfigDTOList = PlacementWordConfigProviderConverter.convertResponseDOList2DTOList(placementWordConfigDOList);
                ResponseUtils.buildSuccessPagingResponse(basePagingResponse, placementWordConfigDTOList, searchRequest,placementWordConfigBSearcher.getTotalCount());
             }

            @Override
            public ScenarioCodeEnum getScenarioEnum() {
                return ScenarioCodeEnum.PLACEMENT_WORD_CONFIG_SEARCH;
            }
        });

        return basePagingResponse;
    }



}
